
<script type="text/javascript">
    $(document).ready(function(){
        $('#bt_test').click(function(){
            $.post('~test/test',{name:'phuc',tuoi:23},function(data){
                alert(data); 
            });
        });
        $('#load').click(function(){
            $.post('~test/getData',{name:'phuc',tuoi:23},function(data){
                $('body').html(data);
            });
        });
        $('#tb_add_comment').click(function(){
            var sCommet =$('#tb_coment').val();
            $.post('~test/getcoment',{},function(data){
                data='<li>'+data+sCommet+'</li>';
                $('#cm').append(data);
            });
        });
        $('#bt_load_product').click(function(){
            $.post('~test/getProduct',{},function(data){
                $('#list_product>table').html(data); 
            });
        });
        $('#bt_add_product').click(function(){
            var name = $('#tb_product_name').val();
            var total = $('#tb_product_total').val();
            $.post('~test/addProduct',{name:name,total:total},function(data){
                $('#list_product>table').prepend(data); 
            });
        });
        $('#bt_load_total_product').click(function(){
            $.post('~test/totalProduct',{},function(data){
                alert("Total product: " + data);
            });
        });
        $('#bt_delete_product').click(function(){
            var id = $('#tb_product_id').val();
            $.post('~test/deleteProduct',{id:id},function(data){
                if(data.indexOf('OK') != -1){
                    alert("DELETE OK");
                }
                else{
                    alert(data);
                }
            });
        });

        $('#bt_update_product').click(function(){
            var id = $('#tb_product_update_id').val();
            var name = $('#tb_product_update_name').val();
            var total = $('#tb_product_update_total').val();
            $.post('~test/updateProduct',{id:id , name:name, total:total},function(data){
                if(data.indexOf('OK') != -1){
                    alert("UPDATE OK");
                }
                else{
                    alert(data);
                }
            });
        });

        // upload file
        $('#bt_upload').click(function(){
            $('#form_upload').submit(); 
        });


        $('#bt_test11111').click(function(){
            if($('#aaaa').val() == ''){
                alert("rong roai");
            } 
            else{
                alert("da chon file roi " + $('#aaaa').val());
            }
        });

        $('#bt_test_json').click(function(){
            $.post('~test/testJson',{},function(data){
                $('#tb_json_data').val(data);

                var dat = JSON.parse(data);
                console.log("name: " + dat.name);
                $.each(dat.image , function(index,value){
                    console.log(index + ' => ' + value);
                });
            });
        });

        $('#heart').click(function(){
            var hear_effect = $(this).find('.heart_effect');
            if(hear_effect.hasClass('hear_active')){
                hear_effect.removeClass('hear_active');
            }
            else{
                hear_effect.addClass('hear_active');
            }
        });

        $('#test_alert').click(function(){
            $.alertBox('hehe','dlksfdlsfklflk'); 
        });
    });

    function uploadComplete(link){
        $('#img_preview').attr("src",link);
    }
</script>

<?php
     /*$oDatabase = new database();
     $sQuery = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
            PREFIX bus: <".URL::getLink("id/bussiness#").">

            SELECT *  
            WHERE {
?uri bus:totalView ?total.
}";
     $result = $oDatabase->loadQuery($sQuery);
     echo '<textarea>';
     var_dump($result);
     echo '</textarea>';*/
 ?>
<div style="min-height: 300px;background-color:#CCC;margin:20px;">
<?php
    //database::log(date('Y-m-d H:i:s' , time()));
    //database::restoreDataBaseFromFile();
?>
</div>

<div style="display: none;">
    <button id="bt_test">CLICK AJAX TEST</button>
    <button id="load">CLICK AJAX TEST</button>
    <button id="refresh" onclick="document.location.reload(true);">LOAD LAI TRANG</button>

    <div id="conment_panel">
        <input id="tb_coment" type="text">
        <input id="tb_add_comment" type="button" value="comment">
        <ul id="cm">
            <li>some comment</li>
        </ul>
    </div>
    <input type="button" value="Load Product" id="bt_load_product">
    <input type="button" value="Total Product" id="bt_load_total_product">
    <div>
        <input type="text" id="tb_product_name">
        <input type="text" id="tb_product_total">
        <input type="button" id="bt_add_product" value="Add Product">
    </div>

    <div>
        <input type="text" id="tb_product_id">
        <input type="button" id="bt_delete_product" value="Delete Product">
    </div>

    <div>
        <input type="text" id="tb_product_update_id">
        <input type="text" id="tb_product_update_name">
        <input type="text" id="tb_product_update_total">
        <input type="button" id="bt_update_product" value="Update Product">
    </div>
    <div id="list_product">
        <table>
            <tr>
                <td>Product Id</td>
                <td>Product Name</td>
                <td>Product Total</td>
            </tr>
        </table>
    </div>

    <script type="text/javascript">
        $(document).ready(function(){
            $('#my-table tr').click(function(){
                var val = $(this).find('td').eq(0).text();
                alert(val);
            });
        });
    </script>

    <form id="form_upload" action="<?php echo URL::getLink('test/uploadAjax'); ?>" method="POST" enctype="multipart/form-data" target="">
        <input type="file" name="file[]">
        <input type="file" name="file[]">
        <img id="img_preview" src="" alt="">
        <input id="bt_upload" type="button" value="Upload">
    </form>
    <iframe id="upload_target" name="upload_target" src="" style=""></iframe>
</div>

<?php
    $a = 1000;
    $b = &$a;
    $b = 2000;
    echo '<h1>Bien a '.$a.'</h1>';
    $ar = array(
        'a' => array(
            '1' => 'klsdfkldf',
            '2' => 'ksdfkldsf dslfk skldfds',
            '3' => '4543sdfsdfsdf'
        ),
        'b' => array(),
        'c' => array(),
    );    
    
    $aa = &$ar['a'];
    $aa['4'] = 'hehehe';
    echo '<textarea>';
    print_r($ar);
    echo '</textarea>';
?>


<h1>TEST ALERT BOX</h1>
<button id="test_alert">test box</button>
<?php
    $testArray = array(
        'name'=> 'trieu quang phuc',
        'tuoi' => 14,
        'image'=>array(
            '1'=>'kldsfkldsfkljdfkldskfl',
            '2'=>'kldsfklsaf ekfjl fkla ',
            '3'=>'kdslfjdkslfjs lkkj ',
        ),
    );

    $str = serialize($testArray);
    echo '<textarea style="width:500px;height:200px;">'.$str.'</textarea>';
    $test = unserialize($str);
    echo '<h1>'.$test['image']['1'].'</h1>';
    echo '<h1>'.$test['name'].'</h1>';
?>
<br><br><br><br><br>
<div id="heart" class="heart">
    <div class="heart heart_content"></div>
    <div class="heart_effect hear_active heart"></div>
</div>
<br><br><br><br><br>
<img class="img_item" src="<?php echo URL::getLink('image/default_user'); ?>" alt="">
<h1>UTF 8 ENCODE: <?php echo utf8_decode('cộng hòa xã hội chủ nghĩa hoa xa hoi'); ?></h1>
<h1>USER: <?php echo $_GET['user']; ?></h1>
<h1>USER: <?php echo $_GET['do']; ?></h1>
<h1>TEST JSON</h1>
<input id="bt_test_json" type="button" value="load_json">
<div>
    <textarea id="tb_json_data" style="width: 600px;height:500px;"></textarea>
</div>



<h1>TIME NOW: <?php echo date('Y-m-d').'T'.date('H:i:s'); ?></h1>
<h1>TIME NOW: <?php echo time(); ?></h1>
<h1>TIME NOW CONVERT FROM <?php $t=time();echo $t; ?> : <?php echo date('Y-m-d H:i:s' , $t); ?></h1>
<h1>CATAGORY BLOCK</h1>
<textarea cols="" rows="" style="width: 700px;height:300px;">
    $param = array(
    'category_uri' => "dsklfklsdfkldsfkdsk'",
    'category_name' => 'skdlfdkslfkdskfdkf',
    'list_categories' => 'list_categories'
    );
    includeBlock('block/categoryBlock', $param); </textarea>


<h1>PRODUCT BLOCK</h1>
<textarea cols="" rows="" style="width: 700px;height:300px;">
    $param = array(
    'aProducts' => array() /* cai mang can truyen,
    array con co nhung thong tin nhu the nay.
    array(
    'uri'=>...,
    'image'=>...,
    'name'=>...,
    'price'=>...,
    'ownUser'=>...,
    'description'=>...,
    );*/
    );
    includeBlock('block/productBlock', $param); 
</textarea>
<h1>REPLACE TEXT</h1>
<?php
    $str = "cong hoa xa hoi chu nghia viet nam doc cong hoa xa hoi cong hoa xa hoi viet nam hanh phuc";
    echo "<p>$str</p>";
    $match = array();
    $test = preg_match_all("#cong hoa#",$str,$match , PREG_OFFSET_CAPTURE);
    echo '<textarea style="width:600px;height:300px;">';
    var_dump($match);
    echo "</textarea>";
    $str = "Cộng hòa xã hội chủ nghĩa việt nam độc lập tự do hạnh phúc";
    echo "<h1>".Text::convert_vi_to_en($str)."</h1>";
?>

<input id="aaaa" type="file">
<input type="button" value="test" id="bt_test11111">